﻿using DevExpress.Data.Filtering;
using DevExpress.ExpressApp.Blazor.Components;
using Volo.Abp.DependencyInjection;
using YAPACS.BusinessObjects.Exams;
using YAPACS.Workflows;

namespace YAPACS.RisServer.Workflows.Exams;

public class GetDefaultFilter : WorkflowBase, IGetDefaultFilter, ITransientDependency
{
    protected override async Task<WorkflowOutput> InvokeCoreAsync(WorkflowInput input)
    {
        var examTimeRange = string.Join(",", [DateTime.Today.ToString("yyyy-MM-dd"), DateTime.Today.ToString("yyyy-MM-dd")]);
        var timeRange = examTimeRange.Split(',');
        var startTime = DateTime.Parse(timeRange[0]).Date;
        var endTime = DateTime.Parse(timeRange[1]).AddDays(1).Date;
        CriteriaOperator criteriaOperator = CriteriaOperator.FromLambda<Exam>(e => e.ExamTime >= startTime && e.ExamTime < endTime);
        input.Add("Output", criteriaOperator);
        return await Task.FromResult(new WorkflowOutput
        {
            Success = true
        });
    }
}
